package cn.sdormitory.controller.canteen;


import cn.sdormitory.canteen.service.FoodSupplierGoodsService;
import cn.sdormitory.canteen.service.FoodSupplierService;
import cn.sdormitory.canteen.vo.CanteenBuyVO;
import cn.sdormitory.canteen.vo.FoodSupplierGoodsVO;
import cn.sdormitory.canteen.vo.FoodSupplierVO;
import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Api(tags = "food-supplier=> 食品供应商")
@RequestMapping("/food/supplier")
public class FoodSupplierController {

    @Autowired
    private FoodSupplierGoodsService foodSupplierGoodsService;
    @Autowired
    private FoodSupplierService foodSupplierService;

    @ApiOperation("getsupplierPageList => 分页查询供应商列表")
    @PostMapping(value = "/getsupplierPageList")
    public CommonResult<CommonPage<FoodSupplierVO>> getsupplierPageList(@RequestBody Map<String, Object> params){
        IPage<FoodSupplierVO> pageList =  foodSupplierService.getPage(params);
        return CommonResult.success(CommonPage.restPage(pageList));
    }

    @ApiOperation("saveOrUpdateFoodSupplierInfo => 新增或修改供应商列表")
    @PostMapping(value = "/saveOrUpdateFoodSupplierInfo")
    public CommonResult<Integer> saveOrUpdateFoodSupplierInfo(@RequestBody FoodSupplierVO vo){
        int num =  foodSupplierService.saveOrUpdateFoodSupplierInfo(vo);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("deleteFoodSupplierById => 删除供应商信息")
    @PostMapping(value = "/deleteFoodSupplierById")
    public CommonResult<Integer> deleteFoodSupplierById(@RequestBody FoodSupplierVO vo){
        int num =  foodSupplierService.deleteFoodSupplierById(vo.getId());
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("deleteFoodSupplierById => 删除供应商信息")
    @PostMapping(value = "/getsupplierGoodsPageList")
    public CommonResult<CommonPage<FoodSupplierGoodsVO>> getsupplierGoodsPageList(@RequestBody Map<String, Object> params){
        IPage<FoodSupplierGoodsVO> pageList =  foodSupplierGoodsService.getPage(params);
        return CommonResult.success(CommonPage.restPage(pageList));
    }

    @ApiOperation("saveOrUpdateFoodSupplierGoodsInfo => 新增或修改供应商商品列表")
    @PostMapping(value = "/saveOrUpdateFoodSupplierGoodsInfo")
    public CommonResult<Integer> saveOrUpdateFoodSupplierGoodsInfo(@RequestBody FoodSupplierGoodsVO vo){
        int num =  foodSupplierGoodsService.saveOrUpdateFoodSupplierGoodsInfo(vo);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("deleteFoodSupplierGoodsById => 新增或修改供应商商品列表")
    @PostMapping(value = "/deleteFoodSupplierGoodsById")
    public CommonResult<Integer> deleteFoodSupplierGoodsById(@RequestBody FoodSupplierGoodsVO vo){
        int num =  foodSupplierGoodsService.deleteFoodSupplierGoodsById(vo.getId());
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}
